import { defineConfig } from 'vite'
import { createVuePlugin as vue } from 'vite-plugin-vue2'
import path from 'path'
import externalGlobals from 'rollup-plugin-external-globals'
// __dirname表示当前文件所处目录 ==> vite_basics_vue2/
const resolve = (dir) => path.resolve(__dirname, dir)

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': resolve('src'), // 识别 @  === vite_basics_vue2/src
    },
    extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
  },
  server: {
    open: true, //自动打开浏览器
    port: 1567, //端口号
    hmr: { overlay: false }, //覆盖
    proxy: {
      '/api': {
        target: 'http://172.17.1.218:9991', // 局域网前后端联调
        // target: 'http://192.168.100.100:6001', // 测试
        // target: 'http://192.168.90.176:6001/', // 房建版
        // target: 'http://pcwp2-api.scrbg.com', // 生产
        changeOrigin: true,
        rewrite: (url) => url.replace(/^\/api/, ''),
      },
    },
  },
  build: {
    rollupOptions: {
      external: ['vue', 'element-plus'],
      plugins: [
        externalGlobals({
          vue: 'Vue',
          vuex: 'Vuex',
          'vue-router': 'VueRouter',
          axios: 'axios',
          'element-ui': 'ELEMENT',
          jquery: '$',
        }),
      ],
    },
  },
})
